import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { Api } from './uri.config';

@Injectable({
  providedIn: 'root'
})
export class LoginService {

  constructor(
    private http: HttpClient
  ) { }

  login(params): Observable<any> {
    return this.http.post(Api.login, params)
      .pipe(
        map((res: { code: string, data: object, message: string }) => {
          return res.code === '200' ? { data: res.data, message: res.message } : { data: null, message: res.message };
        })
      );
  }
}
